package com.atg.atgchat.init.common.factory;

import com.atg.atgchat.init.common.handler.GlobalUncaughtExceptionHandler;
import lombok.AllArgsConstructor;

import java.util.concurrent.ThreadFactory;

/*
author: atg
time: 2025/1/15 9:28
desc: 装饰器模式-线程工厂
*/
@AllArgsConstructor
public class MyThreadFactory implements ThreadFactory {

    private static final GlobalUncaughtExceptionHandler globalUncaughtExceptionHandler = GlobalUncaughtExceptionHandler.getInstance();

    private  ThreadFactory threadFactory;

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = threadFactory.newThread(r);
        // 额外设置异常处理器
        thread.setUncaughtExceptionHandler(globalUncaughtExceptionHandler);
        return null;
    }
}
